package com.example.web;

import cn.dev33.satoken.sso.SaSsoManager;
import lombok.Value;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.mybatis.spring.annotation.MapperScans;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;

@Slf4j
@ComponentScan(basePackages = "com.example.*")
// @MapperScan(value = "com.example.**.mapper") // @MapperScan与@Mapper同时使用导致重复扫描
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class WebApplication extends SpringBootServletInitializer {
    

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(WebApplication.class);
    }


    public static void main(String[] args) {
        SpringApplication.run(WebApplication.class, args);
        
        System.out.println();
        System.out.println("---------------------- Sa-Token SSO 统一认证中心启动成功 ----------------------");
        System.out.println("配置信息：" + SaSsoManager.getServerConfig());
        System.out.println("统一认证登录地址：http://sa-sso-server.com:${server:port}/sso/auth");
        System.out.println("测试前需要根据官网文档修改 hosts 文件，测试账号密码：whxsd1 / whx@gis97");
        System.out.println();

        log.info("服务启动成功！！！！！！！！！！");
    }


    /**
     *  springboot报错，子模块无法读自身的配置文件中的值：Could not resolve placeholder ‘xxx‘ in value “${XXXX}
     *  解决办法
     *  在启动类即有@SpringBootApplication 注解的那个类加上下面内容
     *  可以在配置类上添加@PropertySource注解来加载指定的配置文件
     */
    @Bean
    public static PropertySourcesPlaceholderConfigurer placeholderConfigurer() {
        PropertySourcesPlaceholderConfigurer c = new PropertySourcesPlaceholderConfigurer();
        c.setIgnoreUnresolvablePlaceholders(true);
        return c;
    }

}
